package com.scuec.groupfive.Controller;

import com.scuec.groupfive.service.DailyLearningTrendService;
import com.scuec.groupfive.vo.DailyLearningTrendVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/admin/statistics")
public class DailyLearningTrendController {

    @Resource
    private DailyLearningTrendService dailyLearningTrendService;

    /**
     * 获取用户近三日答题趋势
     * @param userId 用户ID
     * @return 结果集
     */
    @GetMapping("/daily-trend/{userId}")
    public Map<String, Object> getDailyAnswerTrend(@PathVariable Integer userId) {
        Map<String, Object> result = new HashMap<>();
        try {
            List<DailyLearningTrendVO> trendList = dailyLearningTrendService.getDailyAnswerTrend(userId);
            result.put("code", 200);
            result.put("message", "查询成功");
            result.put("data", trendList);
        } catch (Exception e) {
            result.put("code", 500);
            result.put("message", "查询失败: " + e.getMessage());
        }
        return result;
    }
}